﻿#pragma once
#include <vector>
#include <string>
#include <unordered_map>
#include "vmp.h"
#include "VMBinaryCode.h"
#include "VMModule.h"
#include "VMStackFrame.h"


namespace yzrilyzr_vmp{
	EBCLASS(VM){
		std::unordered_map<std::string, std::shared_ptr<VMModule>> modules;
	public:
	VM()=default;
	~VM();
	void loadModule(const std::string & moduleName, const VMBinaryCode & code);
	std::shared_ptr<VMModule> getModule(const std::string & moduleName);
	VMValue callFunction(const std::string & moduleName, const std::string & funcName, VMValue * args, u_index argLen);
	VMValue callFunction(VMModule & module, const std::string & funcName, VMValue * args, u_index argLen);
	VMValue getVariable(const std::string & moduleName, const std::string & varName);
	VMValue getVariable(VMModule & module, const std::string & varName);
	VMValue execute(VMModule & module, VMStackFrame & stackFrame, u_index entryPoint);
	};

}